package com.zhangyj.component;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

public class ToolBar {
	public static class Item {
		private String catption;
		private String event;

		public Item(String catption, String event) {
			super();
			this.catption = catption;
			this.event = event;
		}

		public String getCatption() {
			return catption;
		}

		public void setCatption(String catption) {
			this.catption = catption;
		}

		public String getEvent() {
			return event;
		}

		public void setEvent(String event) {
			this.event = event;
		}
	}

	private String title;
	List<Item> list = new ArrayList<Item>();

	public void put(Item item) {
		this.list.add(item);
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void writer(Writer out) throws IOException {
		out.append("<div class=\"toolbar\">");
		out.append("<table style=\"height:100%;border-collapse:collapse;border-spacing:0px;\">");
		out.append("<tr>");
		out.append("<td class=\"toolbarTitle\">");
		out.append(title);
		out.append("</td>");
		out.append("<td width=\"10px\"/>");
		for (int i = 0; i < list.size(); i++) {
			Item item = list.get(i);
			if (item.event != null) {
				out.append("<td class=\"toolbarItem\" onmouseover=\"this.className='toolbarItemOver'\" onmouseout=\"this.className='toolbarItem'\" onclick=\"");
				out.append(item.event);
				out.append("\">");
			} else {
				out.append("<td>");
			}
			out.append(item.catption);
			out.append("</td>");
		}
		out.append("</tr>");
		out.append("</table>");
		out.append("</div><div style='height:31px;'></div>");
	}
}
